기본형 집착
코드 악취 중 하나. 도메인 개념을 잘 담아낼 수 있는 타입을 정의하지 않고 원시형을 쓰는 상황.
We find many programmers are curiously reluctant to create their own fundamental types which are useful for their domain—such as money, coordinates, or ranges. We thus see calculations that treat monetary amounts as plain numbers, or calculations of physical quantities that ignore units (adding inches to millimeters), or lots of code doing
if (a < upper && a > lower)
.Strings are particularly common petri dishes for this kind of odor: A telephone number is more than just a collection of characters.
—Chapter 3, Refactoring: Improving the design of existing code
관련 리팩토링
- Replace primitive with object
- Replace type code with subclasses
- Conditionals to polymorphism
- Extract class
- Introduce parameter object